package org.ws.task.netty;

import org.ws.task.netty.handler.ActionHandlerRegistry;
import org.ws.task.model.protocol.base.RequestMessage;
import org.ws.task.netty.support.ResponseFuture;
import org.ws.task.model.protocol.base.ResponseMessage;

import java.util.concurrent.ExecutorService;
import java.util.function.Consumer;

public interface NettyClient extends NettyService {

    /**
     * 更新Leader地址
     * @param address
     */
    void setLeaderAddress(String address);

    String getLeaderAddress();

    void heartbeat();

    void clearChannel();

    /**
     * action处理器
     * @param actionHandlerRegistry
     * @param executor
     */
    void actionHandlerRegistry(ActionHandlerRegistry actionHandlerRegistry, ExecutorService executor);

    ResponseMessage sync(String addr, RequestMessage request, long timeout)throws Exception;

    void async(String addr, RequestMessage request, long timeout, Consumer<ResponseFuture> callback)throws Exception;

    void oneWay(String addr, RequestMessage request, long timeout)throws Exception;
}
